/**
 * Author: DXS
 * Date: 2023.02.07
 * Describe: 大屏屏幕尺寸计算
 */
import appConfig from '../settings'

export function pageResize(callback,elementId = 'app-body') {
  let init = () => {
    let _el = document.getElementById(elementId);

    let hScale = window.innerHeight / appConfig.screen.height;
    let wScale = window.innerWidth / appConfig.screen.width;
    let pageH = window.innerHeight;
    let pageW = window.innerWidth;

    let isWider = (window.innerWidth / window.innerHeight) >= (appConfig.screen.width / appConfig.screen.height);
    console.log(isWider);
    if (isWider) {
      _el.style.height = window.innerHeight-85 + 'px';// '100%';
      _el.style.width = pageH * appConfig.screen.width / appConfig.screen.height + 'px';
      _el.style.top = '0px';
      _el.style.left = (window.innerWidth - pageH * appConfig.screen.width / appConfig.screen.height) * 0.5 + 'px';
      console.log(_el.style.width + "," + _el.style.height)
    } else {
      _el.style.width = window.innerWidth + 'px';// '100%';
      _el.style.height = pageW * appConfig.screen.height / appConfig.screen.width + 'px';
      _el.style.top = 0.5 * (window.innerHeight - pageW * appConfig.screen.height / appConfig.screen.width) + 'px';
      _el.style.left = '0px';
      console.log(_el.style.height);
      console.log(_el.style.top);
    }
    if (callback){
      document.documentElement.style.fontSize = (_el.clientWidth / appConfig.screen.scale) + 'px';
    }else {
      document.documentElement.style.fontSize = '15px';
    }


  }
  let resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
  window.addEventListener(resizeEvt, init, false);
  document.documentElement.addEventListener('DOMContentLoaded', init, false);
  init()
}
